package com.aaa.hospital.ManagementEnd.controller;

import com.aaa.hospital.ManagementEnd.pojo.Prescription;
import com.aaa.hospital.ManagementEnd.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/prescrip")
public class PrescriptionController {

    @Autowired
    private PrescriptionService prescriptionService;


    //添加药品
@RequestMapping("/ypinsert")
@ResponseBody
public boolean ypinsert(Integer ydbh,Integer visid,Integer ypid,Integer ypnum,String take,String did){
    System.out.println(ydbh+"a"+visid+"a"+ypid+"a"+ypnum+take+did+"lgq");
      Prescription  prescription=new Prescription(null,visid,ydbh,did,ypid,ypnum,take,null,null,null);
   return prescriptionService.ypinsert(ypid,ydbh,prescription,ypnum);
}


//清除表单数据
    @RequestMapping("/deldiaid")
    @ResponseBody
public boolean deldiaid(Integer ydbh){
        System.out.println(ydbh+"清空数据表");
  return prescriptionService.delByDiaid(ydbh);
}


//削减某条数据的数量
@RequestMapping("/minusNum")
@ResponseBody
public boolean minusNum(Integer ypid,Integer ypnum,Integer ydbh){
    boolean b = prescriptionService.minusNum(ydbh, ypid, ypnum);
   if (b==true){
       Prescription prescription = prescriptionService.queryById(ypid, ydbh);
       if (prescription.getYpnum()<=0){
          return prescriptionService.delById(ypid, ydbh);
       }else {
           return true;
       }
   }
    return false;
}


}
